import { defineStore } from "pinia";

export const loginPinia=defineStore({
    id:"login",
    state:()=>{
        return {
            isAuthenticated:false, //是否登录授权
            userInfo:{} //用户信息
        }
    },
    getters:{

    },
    actions:{
        //获取用户信息
        setUserInfo(userInfo){
            this.userInfo=userInfo;
        },
        //是否有token权限
        setAuthenticated(isAuthenticated){
            this.isAuthenticated=isAuthenticated;
        },
        //清空用户相关信息以及token权限
        clearUserInfo(){
            this.isAuthenticated=false;
            this.userInfo={};
        }
    },
    persist:{
        enabled:true, //开启持久化存储
        strategies:[
            {
                key:"login",
                storage:localStorage
            }
        ]
    }
});
